<template>
	<view class="page">
		<!-- <view class="flex benben-position-layout flex flex-wrap align-center testExamination_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub testExamination_fd0_0'>
				<view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
					<text class='fu-iconfont2  testExamination_fd0_0_c0_c0'>&#xE794;</text>
				</view>
				<text class='testExamination_fd0_0_c1'>订单管理</text>
				<view class='flex flex-wrap align-center testExamination_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view> -->

		<!-- <uv-sticky bgColor="#fff">
			<uv-transition :show="true" mode="fade" duration="300">
				<uv-tabs :scrollable="false" :list="tabslist" @click="click" :current="current" :itemStyle="itemStyle"
					:activeStyle="activeStyle" lineColor="#FC5B03"></uv-tabs>
			</uv-transition>
		</uv-sticky> -->
		<u-sticky v-if="is_violation != 1">
			<u-tabs :list="tabslist" :active-item-style="activeStyle" :bar-style="barStyle" :is-scroll="true"
				:current="current" @change="change"></u-tabs>
		</u-sticky>

		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#FC5B03"></u-loading>
			<view>加载中</view>
		</view>
		<view class="list" v-else>
			<view class="list_item" v-for="(item, index) in list" :key="index" @tap.stop="handleJumpDiy"
				data-type="navigateTo" :data-url="`/pages/my/myOrder/orderDetails?order_id=${item.id}&is_violation=${is_violation}`">
				<view class="item_status flex align-center justify-between">
					<view class="item_date">{{(item.create_at).slice(0,10)}} 预定</view>
					<view class="status_text flex align-center" v-if="is_violation != 1">
						<text v-if="item.status == 1">待付款</text>
						<text v-if="item.status == 2">待取车</text>
						<text v-if="item.status == 3">进行中</text>
						<text v-if="item.status == 4">已完成</text>
						<text v-if="item.status == 5">已取消</text>
						<image :src='STATIC_URL+"208.png"'></image>
					</view>
					<view class="status_text flex align-center" v-else>
						<text v-if="item.vio_status === 0">违章待处理</text>
						<text v-if="item.vio_status == 1">违章处理中</text>
						<text v-if="item.vio_status == 2">处理完成</text>
						<image :src='STATIC_URL+"208.png"'></image>
					</view>
				</view>
				<!-- <view v-if="item.display" class="violation_text flex align-center justify-center" :class="item.isExpired ? 'violation_text_2' : 'violation_text_1'">{{ item.isExpired ? '已超时' : '剩余' }} {{ item.display }}</view> -->
				<view class="item_center">
					<view class="card_info flex align-center">
						<view class="card_info_img">
							<u-lazy-load height="120" border-radius="16" class="card_info_img" :image="item.image"
								:loading-img="loadingImg" :error-img="errorImg" mode="aspectFill"></u-lazy-load>
							<image v-if="item.type == 2" class="car_icon" :src='STATIC_URL+"220.png"' mode="aspectFill">
							</image>
						</view>
						<view class="car_name">
							<view class="car_name_1 flex align-center justify-between">
								<view>{{item.name}}</view>
								<view class="">￥{{Number(item.money)}}</view>
							</view>
							<view class="car_name_2">
								<text>{{item.seats}}座</text>
								<text class="car_name_2_1">丨</text>
								<text>{{item.gearbox}}</text>
								<text class="car_name_2_1">丨</text>
								<!-- <text>{{item.category_name}}</text>
								<text class="car_name_2_1">丨</text> -->
								<text>{{item.model}}</text>
							</view>
						</view>
					</view>

					<view class="order_date flex align-center">
						<view class="date_text">{{(item.take_at).slice(5, 16)}}</view>
						<view class="date_day">
							<view class="date_day_text">{{item.lease_day}}天</view>
							<image :src='STATIC_URL+"266.png"' mode="aspectFill"></image>
						</view>
						<view class="date_text">{{(item.repay_at).slice(5, 16)}}</view>
					</view>
					<view class="address_info flex align-center justify-between">
						<view>
							<view class="address_le flex align-center">
								<image class="address_le_1" :src='STATIC_URL+"225.png"' mode="aspectFill"></image>
								<view class="address_le_2">取还车</view>
								<view class="address_le_3" v-if="item.door_to_door == 2">店员上门送取车</view>
								<view class="address_le_3" v-else>到店取送车</view>

							</view>
							<!-- #ifdef MP-ALIPAY -->
							<view class="label_3" v-if="item.is_freeze > 0">
								<image :src='STATIC_URL+"9.png"'></image>
								<text>芝麻信用 | 免押金</text>
							</view>
							<!-- #endif -->
						</view>
						<view class="address_ri flex align-center">
							<image v-if="item.door_to_door == 2" @tap.stop="openLocation(item.lat, item.lng, item.address, item.address)"
								class="address_ri_img" :src='STATIC_URL+"267.png"' mode="aspectFill"></image>
							<image v-else @tap.stop="openLocation(item.store_lat, item.store_lng, item.store_name, item.store_address)"
								class="address_ri_img" :src='STATIC_URL+"267.png"' mode="aspectFill"></image>
							<view class="address_ri_line"></view>
							<image @tap.stop="getPhone(item.store_phone)" class="address_ri_img"
								:src='STATIC_URL+"268.png"' mode="aspectFill"></image>
						</view>
					</view>
					<template v-if="(item.vio_status === 0 || item.vio_status == 1) && is_violation == 1">
						<view v-if="item.display" class="violation_text flex align-center" :class="item.isExpired ? 'violation_text_2' : 'violation_text_1'">{{ item.isExpired ? '已超时' : '剩余' }} {{ item.display }}</view>
					</template>
					<view class="order_price flex align-center justify-between">
						<view class="order_price_le flex align-center">
							<template v-if="item.status == 1 || item.status == 5">
								<text class="order_price_le_1">应付：</text>
								<text class="order_price_le_2">￥{{Number(item.money)}}</text>
							</template>
							<template v-else>
								<text class="order_price_le_1">已付：</text>
								<text class="order_price_le_2"
									v-if="item.all_items_has_pay == 0">￥{{roundNum(item.money-item.unpay_money, 2)}}</text>
								<text class="order_price_le_2" v-else>￥{{Number(item.money)}}</text>
							</template>
							<template v-if="item.all_items_has_pay == 0">
								<text class="order_price_le_1" style="margin-left: 12rpx;">待付：</text>
								<text class="order_price_le_2">￥{{Number(item.unpay_money)}}</text>
							</template>


						</view>
						<view class="order_price_ri flex align-center justify-center">
							订单详情
						</view>
					</view>
				</view>
			</view>
			<view class="loadmore" v-if="last_page > 1">
				<u-loadmore font-size="24" :status="status" :icon-type="iconType" :load-text="loadText" />
			</view>
		</view>
		<view class="noData" v-if="list.length == 0 && !isShow">
			<image :src='STATIC_URL+"no.png"'></image>
			<view>暂无订单~</view>
		</view>

		<!-- #ifdef MP-TOUTIAO -->
		<image class="kefu" @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/my/customer/customer`"
			src='/static/images/287.png'></image>
		<!-- #endif -->
	</view>
</template>
<script>
	import utils from "@/common/utils/utils.js"
	export default {
		components: {},

		data() {
			return {
				"id": "",
				"name": "",
				"loadingImg": "",
				"errorImg": "",
				"imageUrl": "https://n.sinaimg.cn/spider20240423/618/w1267h951/20240423/00f3-b0424ba924fbe8bb330e2dabf0f7b880.jpg",
				current: 0,
				tabslist: [{
						name: '待付款或待取车',
						id: '1'
					},
					{
						name: '进行中',
						id: '3'
					}, {
						name: '已完成',
						id: '4'
					},
					{
						name: '已取消',
						id: '5'
					},
				],
				itemStyle: {
					'height': '78rpx',
					'fontSize': '26rpx',
					'color': '#666666'
				},
				activeStyle: {
					'color': '#111111',
					'fontWeight': 'bold'
				},
				barStyle: {
					'backgroundColor': '#FC5B03'
				},
				order_status: 1,
				is_violation: 0, // 1违章订单
				timer: null,


				"list": [],
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"iconType": 'flower',
				"loadText": {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				"isShow": true,
			};
		},
		computed: {
		},
		watch: {},
		onLoad(options) {
			let {
				order_status,
				current,
				is_violation
			} = options
			if (order_status !== undefined) this.order_status = order_status;
			if (current !== undefined) this.current = current;
			if (is_violation !== undefined) this.is_violation = is_violation;
			if (is_violation == 1) {
				uni.setNavigationBarTitle({
					title: '违章订单'
				});
			}
		},
		onUnload() {
			clearInterval(this.timer);
		},
		onReady() {

		},
		onShow() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getOrder();
		},
		onHide() {

		},
		onResize() {

		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getOrder();
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {

				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				this.getOrder();
			}, 500)
		},
		onPageScroll(e) {

		},
		methods: {
			getOrder() {
				this.$api.post(global.apiUrls.postOrderList, {
					status: this.order_status,
					is_violation: this.is_violation,
					page: this.page,
					rows: 10
				}).then(res => {
					// console.log(res);
					uni.stopPullDownRefresh();
					this.isShow = false;
					if (res.data.code == 1) {
						this.last_page = res.data.data.totalPage;
						if (this.is_pull) {
							this.list = res.data.data.items;
						} else {
							this.list = this.list.concat(res.data.data.items);
						}
						if (this.is_violation == 1) {
							this.startTimer();
						}
					} else {
						this.$message.info(res.data.info);
					}
				})
			},
			startTimer() {
				this.timer = setInterval(() => {
					this.list = this.list.map(item => ({
						...item,
						...utils.calculateListTimeDiff(item.deadline_time)
					}));
				}, 1000);
			},
			// 打开地图
			openLocation(lat, lng, store_name, store_address) {
				uni.openLocation({
					latitude: Number(lat),
					longitude: Number(lng),
					name: store_name,
					address: store_address,
					success: function() {
						console.log('success');
					},
					fail: function() {

					}
				});
			},
			// 拨打电话
			getPhone(phone) {
				if (!phone) {
					this.$message.info('未获取到门店联系方式，请联系客服');
					return;
				}
				uni.makePhoneCall({
					phoneNumber: phone //仅为示例
				});
			},
			change(index) {
				this.current = index;
				this.order_status = this.tabslist[index].id;
				this.page = 1;
				this.is_pull = true;
				this.isShow = true;
				this.getOrder();
			},
			roundNum(num, precision) {
				var multiplier = Math.pow(10, precision || 0);
				return Math.round(num * multiplier) / multiplier;
			},
		}
	};
</script>
<style lang="scss" scoped>
	.kefu {
		width: 84rpx;
		height: 84rpx;
		position: fixed;
		right: 48rpx;
		bottom: 80rpx;
	}

	.list {
		padding: 0 24rpx;

		.list_item {
			margin-top: 24rpx;
			background: #fff;
			border-radius: 16rpx;
			position: relative;
			.violation_text {
				// position: absolute;
				// top: 0;
				// right: 0;
				border-radius: 0 16rpx 0 0;
				font-size: 22rpx;
				padding: 4rpx 10rpx;
				// color: #fff;
			}
			.violation_text_1 {
				color: #FC5B03;
			}
			.violation_text_2 {
				color: red;
			}

			.item_status {
				padding: 20rpx 24rpx 24rpx 20rpx;
				border-bottom: 2rpx solid #E7E7E7;

				.item_date {
					font-weight: bold;
					font-size: 26rpx;
					color: #111111;
				}

				.status_text {
					font-weight: 400;
					font-size: 26rpx;
					color: #111111;

					image {
						width: 32rpx;
						height: 32rpx;
						margin-left: 8rpx;
					}
				}
			}

			.item_center {
				padding: 24rpx 20rpx;

				.card_info {
					.card_info_img {
						width: 160rpx !important;
						height: 120rpx !important;
						position: relative;

						.car_icon {
							width: 80rpx;
							height: 18rpx;
							position: absolute;
							top: 8rpx;
							right: 8rpx;
						}
					}

					/deep/.u-lazy-item {
						width: 160rpx !important;
						height: 120rpx !important;
					}

					.car_name {
						width: calc(100% - 160rpx);
						padding-left: 22rpx;

						.car_name_1 {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 30rpx;
							color: #111111;
							text-overflow: ellipsis;
							overflow: hidden;
							white-space: nowrap;
						}

						.car_name_2 {
							margin-top: 12px;
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 22rpx;
							color: #666666;
							text-overflow: ellipsis;
							overflow: hidden;
							white-space: nowrap;

							.car_name_2_1 {
								color: #CCCCCC;
							}
						}
					}
				}

				.order_date {
					margin-top: 24rpx;

					.date_text {
						font-weight: 500;
						font-size: 30rpx;
						color: #111111;
					}

					.date_day {
						display: flex;
						flex-direction: column;
						align-items: center;
						margin: 0 24rpx;

						.date_day_text {
							font-weight: 400;
							font-size: 22rpx;
							color: #999999;
						}

						image {
							width: 104rpx;
							height: 8rpx;
						}
					}
				}

				.address_info {
					margin-top: 16rpx;

					.address_le {
						.address_le_1 {
							width: 18rpx;
							height: 12rpx;
							margin-right: 8rpx;
						}

						.address_le_2 {
							font-weight: bold;
							font-size: 26rpx;
							color: #111111;
							margin-right: 12rpx;
						}

						.address_le_3 {
							font-weight: bold;
							font-size: 26rpx;
							color: #FC5B03;
						}
					}

					.address_ri {
						.address_ri_line {
							width: 2rpx;
							height: 32rpx;
							background: #E7E7E7;
							margin: 0 24rpx;
						}

						.address_ri_img {
							width: 60rpx;
							height: 60rpx;
						}
					}

					.label_3 {
						display: inline-block;
						padding: 3rpx 9rpx;
						background: rgba(22, 119, 255, 1);
						color: #fff;
						font-size: 22rpx;
						border-radius: 8rpx;
						margin-top: 10rpx;

						image {
							width: 22rpx;
							height: 22rpx;
							margin-right: 10rpx;
							vertical-align: middle;
							transform: translateY(-2rpx);
						}
					}
				}

				.order_price {
					padding-top: 20rpx;
					border-top: 2rpx solid #f7f7f7;
					margin-top: 24rpx;

					.order_price_le {
						.order_price_le_1 {
							font-weight: 400;
							font-size: 26rpx;
							color: #111111;
						}

						.order_price_le_2 {
							font-weight: 400;
							font-size: 26rpx;
							color: #EF2E28;
						}
					}


					.order_price_ri {
						width: 180rpx;
						height: 64rpx;
						border-radius: 80rpx;
						border: 2rpx solid #E7E7E7;
						font-weight: 400;
						font-size: 26rpx;
						color: #111111;
					}

					.order_price_ri_xun {
						width: 180rpx;
						height: 64rpx;
						border-radius: 80rpx;
						border: 2rpx solid #FC5B03;
						font-weight: 400;
						font-size: 26rpx;
						color: #FC5B03;
					}
				}
			}
		}
	}

	.personalInformation_fd1_0 {
		padding: 28rpx 0;
		border-top: 2rpx solid #eee;
	}

	.personalInformation_fd1_0_c0 {
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.6);
	}

	.personalInformation_fd1_1_c1 {
		font-size: 28rpx;
		font-weight: 400;
		color: #111;
		text-align: right;
	}


	.feedback_fd4_0 {
		width: 640rpx;
		border-radius: 80rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #fff;
		margin: 0rpx 32rpx 0rpx 32rpx;
		height: 84rpx;
		line-height: 84rpx;
		text-align: center;
		background: #FC5B03;
	}

	.feedback_flex_4 {
		width: 750rpx;
		height: 120rpx;
		overflow: hidden;
		position: fixed;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		display: flex;
		justify-content: center;
		background: #fff;
	}




	.testExamination_fd1_0 {
		margin: 0rpx 16rpx 0rpx 0rpx;
		padding: 40rpx 32rpx 24rpx 32rpx;
	}

	.testExamination_fd1_0_c0 {
		width: 36rpx;
		height: 36rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
	}

	.testExamination_fd1_0_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 700;
		color: #333333;
	}

	.testExamination_notAnfd1_1_c0 {
		background: rgba(244, 250, 255, 1);
		background-size: 100% !important;
		width: 750rpx;
		height: 80rpx;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.testExamination_anfd1_1_c0 {
		background: rgba(244, 250, 255, 1);
		background-size: 100% !important;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		padding: 0rpx 32rpx 0rpx 32rpx;
		width: 750rpx;
		height: 80rpx;
	}

	.testExamination_areafd1_1_c0 {
		min-height: 80rpx;
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.testExamination_notAnfd1_1_c0_c0_c0 {
		width: 36rpx;
		height: 36rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
	}

	.testExamination_notAnfd1_1_c0_c0_c1 {
		margin: 0rpx 20rpx 0rpx 0rpx;
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 700;
		color: #1593FF;
	}

	.testExamination_notAnfd1_1_c0_c0_c2 {
		font-weight: 700;
		font-size: 32rpx;
		color: #1593FF;
		line-height: 45rpx;
		text-decoration: none;
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.testExamination_anfd1_1_c0_c0_c0 {
		width: 36rpx;
		height: 36rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
	}

	.testExamination_anfd1_1_c0_c0_c1 {
		margin: 0rpx 20rpx 0rpx 0rpx;
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 700;
		color: #1593FF;
	}

	.testExamination_anfd1_1_c0_c0_c2 {
		font-weight: 700;
		font-size: 32rpx;
		color: #1593FF;
		line-height: 45rpx;
		text-decoration: none;
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.testExamination_areafd1_1_c0_c0 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 40rpx 0rpx;
	}

	.testExamination_areafd1_1_c0_c0_c0 {
		margin: 0rpx 0rpx 24rpx 0rpx;
	}

	.testExamination_areafd1_1_c0_c0_c0_c0_c0 {
		margin: 0rpx 0rpx 24rpx 0rpx;
	}

	.testExamination_areafd1_1_c0_c0_c0_c0_c0_c0 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		margin: 0rpx 15rpx 0rpx 0rpx;
	}

	.testExamination_areafd1_1_c0_c0_c0_c0_c0_c1 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
	}

	.testExamination_areafd1_1_c0_c0_c0_c0_c1_c0 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: rgba(21, 147, 255, 1);
	}

	.testExamination_areafd1_1_c0_c0_c0_c0_c1_c1 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
	}

	.testExamination_areafd1_1_c0_c0_c0_c0_c1_c2 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
	}

	.testExamination_areafd1_1_c0_c0_c0_c0_c1_c3 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		margin: 0rpx 32rpx 0rpx 0rpx;
	}

	.testExamination_areafd1_1_c0_c0_c0_c0_c1_c4 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
	}

	.testExamination_areafd1_1_c0_c0_c0_c0_c1_c5 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
	}

	.testExamination_areafd1_1_c0_c0_c0_c1 {
		font-size: 26rpx;
		color: rgba(191, 191, 191, 1);
	}

	.testExamination_areafd1_1_c0_c0_c1 {
		background: rgba(242, 242, 242, 1);
		background-size: 100% !important;
		width: 602rpx;
		height: 16rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		background-size: 100% auto !important;
	}

	.testExamination_progress1_areafd1_1_c0_c0_c1 {
		background: rgba(21, 147, 255, 1);
		background-size: 100% !important;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
	}

	.testExamination_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.testExamination_fd0_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: #111;
	}

	.testExamination_fd0_0_c1 {
		font-size: 32rpx;
		font-weight: bold;
		color: #111111;
	}

	.testExamination_fd0_0_c2 {
		width: 36rpx;
		height: 36rpx;
	}

	.testExamination_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: #f6f7fb;
		background-size: 100% auto !important;
	}
</style>